<?php 
namespace plugin;
class Admin extends \Plugin {
	
	protected $_admin_auth = 1;

	public function index(){
		$slides = \Ebcms::db() -> select('slide', '*', [
			'ORDER' => [
				'weight' => 'ASC',
				'id' => 'ASC',
			]
		]);
		$this -> assign('slides', $slides);
		return \mylib\Response::html($this -> fetch());
	}

	public function add(){
		if (\Ebcms::isPost()) {
			\Ebcms::db() -> insert('slide', [
				'title'=>\mylib\Input::post('title'),
				'url'=>\mylib\Input::post('url'),
				'image'=>\mylib\Input::post('image'),
				'description'=>\mylib\Input::post('description'),
				'weight'=>\mylib\Input::post('weight'),
			]);
			return $this -> success('操作成功！', plugin_url('/slide/admin/index'));
		}else{
			return \mylib\Response::html($this -> fetch());
		}
	}

	public function edit(){
		if (\Ebcms::isPost()) {
			\Ebcms::db() -> update('slide', [
				'title'=>\mylib\Input::post('title'),
				'url'=>\mylib\Input::post('url'),
				'image'=>\mylib\Input::post('image'),
				'description'=>\mylib\Input::post('description'),
				'weight'=>\mylib\Input::post('weight'),
			], [
				'id'=>\mylib\Input::post('id')
			]);
			return $this -> success('操作成功！', plugin_url('/slide/admin/index'));
		}else{
			$data = \Ebcms::db() -> get('slide', '*', ['id'=>\mylib\Input::get('id')]);
			$this -> assign('data', $data);
			return \mylib\Response::html($this -> fetch());
		}
	}

	public function del(){
		if (\Ebcms::isAjax()) {
			\Ebcms::db() -> delete('slide', [
				'id'=>\mylib\Input::post('id'),
			]);
			return $this -> success('操作成功！');
		}
	}
}